import Mock from "mockjs";

let { data } = Mock.mock({
  "data|200": [
    {
      num: /\d{15}/,
      "id|+1": 10001,
      "amount|200-2000": 200,
      "money|0-10": 0,
      consignee: "@cname",
      address: "@county(true)",
      "pay|1": ["支付宝", "微信支付", "银行转账"],
      "status|1": ["已发货", "代发货", "待支付", "已取消"],
    },
  ],
});

interface ParamsType {
  pageSize: number;
  currentPage: number;
}
interface RemoveParamsType {
  goodsId: number;
}

class OrderServer {
  getData(params: ParamsType) {
    const { pageSize, currentPage } = params;
    const result = data.slice(
      (currentPage - 1) * pageSize,
      pageSize * currentPage
    );
    return new Promise((resolve) => {
      resolve({
        status: 0,
        result: result,
        count: data.length,
      });
    });
  }
  removeData(removeParams: RemoveParamsType) {
    const { goodsId } = removeParams;
    data = data.filter((item: any) => item.goodsId !== goodsId);
    return new Promise((resolve) => {
      resolve({
        status: 0,
        msg: "删除成功",
      });
    });
  }
}

const order = new OrderServer();

export default order;
